import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/handle/xindong_user_handle.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/routes/user/profile/xindong_profile_yemian.dart';
import 'package:xindong/routes/userspace/xindong_kongjian_ctr.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_app_bar_icon_button.dart';
import 'package:xindong/widgets/dialog/xindong_options_sheet.dart';

class XinDongKongJianAppBar extends StatelessWidget {
  const XinDongKongJianAppBar({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<XinDongKongJianCtr>(
      id: "appBarAlpha",
      builder: (controller) {
        final isWhite = controller.isTransparentAppBar;
        final textColor = isWhite ? Colors.white : DZColors.titleColor;
        final backgroundColor = DZColors.appBar.withOpacity(controller.appBarAlpha);
        final isSelf = controller.userspace?.isSelf == true;
        return XinDongAppBar(
          "",
          leading: XinDongAppBarIconButton(isWhite: isWhite),
          backgroundColor: backgroundColor,
          brightness: controller.brightness,
          elevation: 0,
          actions: isSelf ? mineRightItem(isWhite) : otherRightItem(isWhite),
          titleView: controller.appBarAlpha < 0.7
              ? null
              : Column(
                  children: [
                    Text(
                      controller.userspace?.getName ?? "",
                      style: TextStyle(fontSize: 16, color: textColor),
                    ),
                    if (!isSelf)
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(Icons.location_on_outlined, size: 12, color: textColor),
                          Text(
                            controller.distanceText,
                            style: TextStyle(fontSize: 12, color: textColor),
                          ),
                        ],
                      )
                  ],
                ),
        );
      },
    );
  }

  List<Widget> otherRightItem(bool isWhite) {
    return [
      XinDongAppBarIconButton(
        isWhite: isWhite,
        icon: Icons.more_horiz_rounded,
        onTap: () {
          XinDongOptionsSheet.show(
            dataList: const ["举报", "拉黑"],
            onSelect: (index) {
              if (index == 0) {
                XinDongPageSingleton.instance.jumpToReport(userId: XinDongKongJianCtr.to.userspace!.uid);
                // } else if () {
                //   bool result = await trendHandle.htmy_requestShield(model);
                //   if (result) {
                //     deleteSuccessCallback(model);
                //     // 详情页要做返回操作
                //     if (isDetails) Navigator.pop(currentContext());
                //   }
              } else if (index == 1) {
                XinDongUserHandle().blackListAdd(userId: XinDongKongJianCtr.to.userspace!.uid);
              }
            },
          );
        },
      )
    ];
  }

  List<Widget> mineRightItem(bool isWhite) {
    return [
      XinDongAppBarIconButton(
        isWhite: isWhite,
        icon: Icons.edit_note,
        onTap: () => XinDongPageSingleton.instance.pushYeMian(const XinDongProfileYeMian()),
      )
    ];
  }
}
